﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_SelectSupply : System.Web.UI.Page
{
    static PagedDataSource pagedDataSource = new PagedDataSource();
    static List<Supply> list = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Supply supply = new Supply();
            list = SupplyManager.FindBlurSupply(supply);
            pagedDataSource.DataSource = list;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = 0;
            pagedDataSource.AllowPaging = true;
            this.DataList1.DataSource = pagedDataSource;
            this.DataList1.DataBind();
        }
    }
    protected void btnFind_Click(object sender, EventArgs e)
    {
        if (txtSupplyName.Text != null && txtSupplyName.Text != "")
        {
            Supply supply = new Supply();
            supply.SupplyName = txtSupplyName.Text.Trim();
            list = SupplyManager.FindBlurSupply(supply);
            pagedDataSource.DataSource = list;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = 0;
            pagedDataSource.AllowPaging = true;
            this.DataList1.DataSource = pagedDataSource;
            this.DataList1.DataBind();
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        pagedDataSource.DataSource = list;
        pagedDataSource.PageSize = 10;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.CurrentPageIndex--;
        DataList1.DataSource = pagedDataSource;
        DataList1.DataBind();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        pagedDataSource.DataSource = list;
        pagedDataSource.PageSize = 10;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.CurrentPageIndex++;
        DataList1.DataSource = pagedDataSource;
        DataList1.DataBind();
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "selectData")
        {
            Supply supply = SupplyManager.FindBySupplyId(Convert.ToInt32(e.CommandArgument.ToString()));
            ClientScript.RegisterStartupScript(this.GetType(), "", "var rel=new Array('" + e.CommandArgument.ToString() + "','" + supply.SupplyName + "'); window.returnValue = rel; window.close();", true);
        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (pagedDataSource.IsFirstPage)
            {
                ((LinkButton)e.Item.FindControl("LinkButton2")).Enabled = false;
            }
            if (pagedDataSource.IsLastPage)
            {
                ((LinkButton)e.Item.FindControl("LinkButton3")).Enabled = false;
            }
        }
    }
}
